@extends('manage.layout')

@section('content')
    <section class="content-header">
        <h1>
            客户列表
        </h1>
        <ol class="breadcrumb">
            <li><a href="#"><i class="fa fa-dashboard"></i> Home</a></li>
            <li><a href="#">Client</a></li>
            <li class="active">Client List</li>
        </ol>
        <div class="input-group margin">
            <form action="{{ url('client') }}" method="get">
                {{--{{ csrf_field() }}--}}
                <select style="width: 150px" id="sel"  name="type" class="form-control" onchange="select()">
                    @foreach($searchtype as $value)
                        <option value="{{ $value['id'] }}">{{ $value['searchtype'] }}</option>
                    @endforeach
                </select>

                <div style="float: left" id="form">
                    <input id="datepicker" style="width: 200px"  name="param" type="text" class="form-control">
                    {{--<input style="width: 200px" type="text" name="param" class="form-control" id="datepicker">--}}
                </div>
                <input  type="submit" class="btn btn-info btn-flat" value="Go!">
            </form>
            <script>
                function select() {
                    var val = $('#sel option:selected').val();
                    console.log(val);
                    if(val == 2) {
                        $('#datepicker').datepicker({
                            autoclose: true,
                            format: 'yyyy-mm-dd'
                        });
                    }
                    else{
                        $('#datepicker').datepicker('remove');
//                        $('#datepicker').datepicker('remove');
//                        $('#form').html('<input style="width: 200px" id="data" name="param" type="text" class="form-control">');
                    }
                }
            </script>
        </div>
    </section>

    <!-- Main content -->
    <section class="content">
        <div class="row">
            <div class="col-xs-12">
                <div class="box">
                    <div class="box-header">
                        <h3 class="box-title">内容</h3>
                        <span style="float:right;color: #bbb">共{{$count}}条结果</span>
                    </div>
                    <!-- /.box-header -->
                    <div class="box-body">
                        <table class="table table-bordered table-hover">
                            <thead>
                            <tr>
                                <th>ID</th>
                                {{--<th>权重</th>--}}
                                <th>
                                    更新时间&nbsp;&nbsp;
                                    <a href="/client?type={{$search}}&param={{$param}}&orderBy=1"><i class="fa fa-arrow-up"></i></a>&nbsp;&nbsp;
                                    <a href="/client?type={{$search}}&param={{$param}}&orderBy=2"><i class="fa fa-arrow-down"></i></a>
                                </th>
                                <th>公司名称</th>
                                <th>所属行业</th>
                                <th>第一联系人</th>
                                <th style="min-width: 140px">第一联系人电话</th>
                                {{--<th>第二联系人</th>--}}
                                {{--<th style="min-width: 140px">第二联系人电话</th>--}}
                                {{--<th>公司规模</th>--}}
                                <th>所在地</th>
                                {{--<th>公司地址</th>--}}
                                <th>添加人</th>
                                <th>图片</th>
                                {{--<th>备注</th>--}}
                                <th style="min-width: 80px">操作</th>
                            </tr>
                            </thead>
                            <tbody>
                            @foreach($client as $key=>$c)
                                <tr>
                                    <td style="min-width: 40px">{{ $c['id'] }}</td>
                                    {{--<td style="min-width: 50px">{{ $c['rank'] }}</td>--}}
                                    <td style="min-width: 150px">{{ $c['update_time'] }}</td>
                                    <td >{{ $c['company'] }}</td>
                                    <td style="max-width: 150px">{{ App\Model\Industry::find($c['industry_id'])['name'] }}</td>
                                    <td>{{ $c['first_name'] }}</td>
                                    <td>{{ $c['first_phone'] }}</td>
                                    {{--<td style="min-width: 100px">{{ $c['second_name'] }}</td>--}}
                                    {{--<td>{{ $c['second_phone'] }}</td>--}}
                                    {{--<td style="min-width: 100px">--}}
                                        {{--@if($c['scale'] ==0 )20人以下--}}
                                        {{--@elseif($c['scale'] ==1)50人以下--}}
                                        {{--@elseif($c['scale'] ==2)100人以下--}}
                                        {{--@elseif($c['scale'] ==3)200人以下--}}
                                        {{--@elseif($c['scale'] ==4)200人以上--}}
                                        {{--@endif--}}
                                    {{--</td>--}}
                                    <td style="min-width: 80px">{{ $c['loc'] }}</td>
                                    {{--<td>{{ $c['address'] }}</td>--}}
                                    <td>
                                        @foreach($users as $k=>$v)
                                            @foreach($v['user_detail'] as $d_k=>$d_v)
                                                @if($c['dd_id'] == $d_v['user_id'])
                                                    {{ $d_v['user_name'] }}({{ $v['user_department'] }})
                                                @endif
                                            @endforeach
                                        @endforeach
                                            <br><button class="btn btn-primary btn-xs" type="submit" onclick="ddid_change({{ $c['id'] }})">更改</button>
                                    </td>
                                    <td>
                                        <div id="md-{{$key}}" class="md-trigger" style="width:100px;height:100px;margin: auto">
                                            @if($picture[$key]!=0)
                                                @foreach($picture[$key] as $k=>$v)
                                                    <img @if($k != 0)style="display: none" @endif layer-src="http://vipyipoint.oss-cn-beijing.aliyuncs.com/{{ $v }}" src="http://vipyipoint.oss-cn-beijing.aliyuncs.com/{{ $v }}" width="100px" height="100px">
                                                @endforeach
                                            @else没有图片
                                            @endif
                                        </div>
                                    </td>
                                    {{--<td style="min-width: 50px">{{ $c['remark'] }}</td>--}}
                                    <td style="min-width: 100px">
                                        <a class="btn btn-info btn-xs" href="/client/client_detail/{{ $c['id'] }}">客户详情</a>
                                        {{--<a id="status" class="btn btn-success btn-xs"  href="{{ url('clueEdit/'.$c['id']) }}">进行<a>--}}
                                        <div class="btn-group">
                                            <button type="button" class="btn btn-warning btn-xs">@if($c['status'] == 0)跟进中@elseif($c['status'] == 1)待观察@elseif($c['status'] == 2)已成单@endif</button>
                                            <button id="button" type="button" class="btn btn-warning btn-xs dropdown-toggle" data-toggle="dropdown">
                                                <span class="caret"></span>
                                                <span class="sr-only">Toggle Dropdown</span>
                                            </button>
                                            <ul class="dropdown-menu" role="menu">
                                                <li><a href="javascript:clientStatus('{{ $c['id'] }}',0)">跟进中</a></li>
                                                <li><a href="javascript:clientStatus('{{ $c['id'] }}',1)">待观察</a></li>
                                                <li><a href="javascript:clientStatus('{{ $c['id'] }}',2)">已成单</a></li>
                                            </ul>
                                        </div>

                                        {{--<div class="btn-group">
                                            <button type="button" class="btn btn-info btn-sm">更改添加人</button>
                                            <button id="button" type="button" class="btn btn-info btn-sm dropdown-toggle" data-toggle="dropdown">
                                                <span class="caret"></span>
                                                <span class="sr-only">Toggle Dropdown</span>
                                            </button>
                                            <ul class="dropdown-menu" role="menu">
                                                @foreach($users as $k=>$v)
                                                <li><a href="javascript:ddid_select('{{ $c['id'] }}',{{ $v['user_id'] }})">{{ $v['user_name'] }} - {{ $v['user_department'] }}</a></li>
                                                @endforeach
                                            </ul>
                                        </div>--}}


                                    </td>
                                </tr>

                            @endforeach
                            </tbody>
                        </table>
                    </div>
                    <!-- /.box-body -->
                    <div style="text-align: center;">
                        {{ $client->appends(['type'=>$search,'orderBy'=>$orderBy,'param'=>$param,'count'=>$count])->links() }}
                    </div>
                </div>
            </div>
            <!-- /.col -->
        </div>
        <!-- /.row -->
        {{--<div id="ddid_change" style="width:100%; position: absolute">
            <div class="layui-tab layui-tab-brief" style="position: absolute">
                <ul class="layui-tab-title" style="max-width: 370px">
                    @foreach($users as $k=>$v)
                        <li>{{ $v['user_department'] }}</li>
                    @endforeach
                </ul>
                <div class="layui-tab-content">
                    @foreach($users as $k=>$v)
                        --}}{{--<div class="layui-tab-item" style="border:1px solid #f00">
                        {{ print_r($v['user_detail']) }}
                            </div>--}}{{--
                        <div class="layui-tab-item">
                        @foreach($v['user_detail'] as $d_k=>$d_v)
                            {{ $d_v['user_name'] }} &nbsp;&nbsp;
                        @endforeach
                        </div>
                    @endforeach
                </div>
            </div>

        </div>--}}
    </section>
@stop
@section('script')
    <script>
        for(var i=0;i<'{{count($client)}}';i++){
            layer.photos({
                photos: "#md-"+i
                ,anim: 5 //0-6的选择，指定弹出图片动画类型，默认随机（请注意，3.0之前的版本用shift参数）
            });
        }
        //禁用,启用
        function clientStatus(id,status) {
            console.log(id);
            console.log(status);
            $.ajax({
                url: '/client/clientStatus',
                type: "GET",
                data: {id:id,status:status},
                dataType: "json",
                success: function(res) {
                    console.log(res);
                    if(res.code == 100) {
                        layer.msg(res.msg, {time:1500, icon:6});
                        window.location.href=window.location.href;
                    }
                    else {
                        layer.msg(res.msg, {time:1500, icon:5});
                    }
                }
            });
        }

        //更改添加人(所属员工)select
        function ddid_select(id,user_id) {
            layer.closeAll();
            $.ajax({
                url: '/client/clientddid_select',
                type: "GET",
                data: {id:id,user_id:user_id},
                dataType: "json",
                success: function(res) {
                    console.log(res);
                    if(res.code == 100) {
                        layer.msg(res.msg, {time:1500, icon:6});
                        history.go(0);
                    }
                    else {
                        layer.msg(res.msg, {time:1500, icon:5});
                    }
                }
            });
            location.reload();
        }

        //更改添加人(所属员工)layui
        function ddid_change($id) {
            layer.open({
                type:1,
                title:'更改添加人',
                scrollbar: false,
                /*skin: 'layui-layer-rim', //加上边框
                area: ['420px', '240px'], //宽高
                maxWidth: '420px',*/
                closeBtn:0,
                shadeClose:true,
                area: ['90%', '90%'],
                content: '<div class="layui-tab layui-tab-brief"><ul class=\"layui-tab-title\" style="border-bottom:0px">@foreach($users as $k=>$v)<li style="float:left">{{ $v['user_department'] }}</li>@endforeach</ul> <div class="layui-tab-content" style="clear:both; border-top:1px solid #ccc">@foreach($users as $k=>$v)<div class="layui-tab-item">@foreach($v['user_detail'] as $d_k=>$d_v)<a onclick="ddid_select('+$id+', {{ $d_v['user_id'] }})">{{ $d_v['user_name'] }}</a> &nbsp;&nbsp;@endforeach</div>@endforeach</div> </div>'
            });
        }
        layui.use('element', function(){
            var element = layui.element();

            //…
        });

    </script>
@stop